class Solution {
    public int findJudge(int n, int[][] trust) {
        int m = trust.length;
        int ret = -1;
        int[] arr = new int[n + 1];
        for (int i = 0; i < m; i++) {
            arr[trust[i][1]]++;
        }
        for (int i = 1; i <= n; i++) {
            if (arr[i] == n - 1) {
                ret = i;
                break;
            }
        }
        for (int i = 0; i < m; i++) {
            if (trust[i][0] == ret) return -1;
        }
        return ret;
    }
}